<template>
	<div class="container">
		<div class="proocessBox" v-show="processMark">
			<el-progress :text-inside="true" :stroke-width="36" :percentage="processNum.toFixed(2) * 100"></el-progress>
		</div>
		<h3 class="header-title clearfix">
			<span></span>
			<p>人才库</p>
			<!-- <p class="fr el-icon-plus" @click="openInputDialog"> 新增项目</p> -->
		</h3>
		<!-- 项目筛选 -->
		<div class="seachBox clearfix">
			<el-row>
				<el-col :span="6"><span>姓名</span>
					<el-input v-model="formSeach.name"></el-input>
				</el-col>
				<el-col :span="6"><span>性别</span>
					<el-input v-model="formSeach.sex"></el-input>
				</el-col>
				<el-col :span="6"><span>手机号</span>
					<el-input v-model="formSeach.telnum"></el-input>
				</el-col>
			</el-row>
			<el-row>
				<el-col :span="6"><span>职能</span>
					<!-- <el-input v-model="formSeach.tradeName"></el-input> -->
					<el-cascader ref="cascader" v-model="formSeach.tradeCode" :options="workersList" clearable
						@change="handleChangeCode(formSeach.tradeCode, '11')"></el-cascader>
				</el-col>
				<el-col :span="6"><span>职位名称</span>
					<el-input v-model="formSeach.jobName"></el-input>
				</el-col>
				<el-col :span="6"><span>居住地</span>
					<el-input v-model="formSeach.region"></el-input>
				</el-col>


				<el-col :span="6">
					<button class="serchBtn btn1" @click="initBase">查询</button>
					<el-upload class="upload-demo" action :show-file-list="false" :limit="3" :http-request="getExcel"
						v-show="userInfo.grade != '20'" accept=".xlsx,.xls">
						<el-button size="small" class="serchBtn btn2" v-show="userInfo.grade != '20'">导入</el-button>
					</el-upload>

				</el-col>
			</el-row>
		</div>
		<!-- 主体列表栏 -->
		<comTable :options="tableData" @stopProject="stopProject" class="projectTab" @statuss="statuss"
			@lookResume="lookResume" @uploadResume="uploadResume" @editData="editData" @markDia="markDia"
			@upadteDetail="upadteDetail" @remarkDetail="remarkDetail" @signUp="signUp" @changeRemark="changeRemark"></comTable>
		<perMgAddRemarks ref="remark" :options="remarksData"></perMgAddRemarks>
		<!-- input弹窗 -->
		<comInput :options="inputData" @subData="subData"></comInput>
		<comResume :options="remuseData"></comResume>
		<matMgUploadResume :options="uploadData" @updateView="updateView"></matMgUploadResume>
		<el-dialog :visible.sync="toolDialog.exportShow" :before-close="handleClose" :width="widPersnt">
			<h2 class="center">{{ toolDialog.title }}</h2>
			<div class="exportBox" v-show="toolDialog.title == '导入数据'">
				<comTable :options="exportData" class="projectTab"></comTable>
				<div class="pageBox" v-show="allData.length != 0">
					<el-pagination @size-change="handleSizeChangeExport" @current-change="pageChangeExport"
						:current-page="curExport" :page-sizes="[10, 20, 30, 50, 100]" :page-size="pageSizeExport"
						layout="total, sizes, prev, pager, next, jumper" :total="totalExport" background></el-pagination>
				</div>
				<button class="serchBtn exporBtn" @click="subExport()">确认导入</button>
			</div>

			<div class="remarks-content" v-show="toolDialog.title == '备注'">
				<el-input type="textarea" :rows="2" placeholder="请输入内容" v-model="textareaRemark"></el-input>
				<el-button class="sub" size="small" style="width: 100px;" type="primary" @click="submiteRemark"
					v-show="toolDialog.title == '备注'">确定</el-button>
			</div>

			<div class="inputBox" v-show="toolDialog.title == '招聘信息录入'">
				<el-form :inline="true" :model="formUser" class="demo-form-inline" label-width="175px">
					<el-form-item v-for="item in formItem.item" :label="item.label" class="itemForm">
						<el-input v-model="formExport[item.title]" :placeholder="item.placeholder" class="width"
							v-show="item.label != '项目归属' && item.label != '状态' && item.label != '备注' && item.label != '面试时间' && item.label != '简历' && item.label != '职能'">
						</el-input>
						<el-select v-model="formExport[item.title]" placeholder="请选择项目" filterable clearable class="width"
							v-show="item.label == '项目归属'" @change="getLabel">
							<el-option v-for="(item, index) in belongList" :label="item.projectBlongs" :value="item.projectId"
								:key="index"></el-option>
						</el-select>

						<p class="pBox" v-show="item.label == '简历'">
							<span class="upIcon el-icon-upload2" @click="uploadResume(formExport)"
								v-show="!remuseData.list.length > 0">上传简历</span>
							<span class="upIcon el-icon-folder-opened" @click="lookResume(formExport)"
								v-show="remuseData.list.length > 0">查看简历</span>

						</p>
						<el-select v-model="formExport[item.title]" placeholder="请选择工作状态" v-show="item.label == '状态'"
							@change="getType" class="width">
							<el-option label="沟通" value="1"></el-option>
							<el-option label="通知面试" value="2"></el-option>
							<el-option label="实到面试" value="3"></el-option>
							<el-option label="通知复试" value="4"></el-option>
							<el-option label="实到复试" value="5"></el-option>
							<el-option label="录取" value="6"></el-option>
							<el-option label="到岗" value="7"></el-option>
						</el-select>

						<el-cascader ref="cascader" v-model="formSeach.tradeCode" class="width" :options="workersList" clearable
							@change="handleChangeCode(formSeach.tradeCode, '22')" v-if="item.label == '职能'">
						</el-cascader>


						<el-input type="textarea" v-model="formExport[item.title]" class="width" v-show="item.label == '备注'">
						</el-input>
						<el-date-picker v-model="serchKey" type="datetime" placeholder="选择面试时间" class="width"
							v-show="item.label == '面试时间'">
						</el-date-picker>

					</el-form-item>


				</el-form>
				<p class="textAl"><button class="serchBtn exporBtn" @click="sureEnter">确认导入</button></p>
			</div>
			<div class="inputBox" v-show="toolDialog.title == '修改明细'">
				<div class="updateMark" v-for="item in updateList">
					<h4>{{ item.updateTime }}</h4>
					<div class="updateItem">
						<p>修改类型：{{ item.garedName }}</p>
						<p>修改前内容：{{ item.changedFront }}</p>
						<p>修改后内容：{{ item.changedQueen }}</p>
						<p class="red">修改人：{{ item.userName }}</p>
					</div>
				</div>

			</div>
			<div class="inputBox" v-show="toolDialog.title == '备注明细'">
				<div class="updateMark" v-for="item in remarkList">
					<h4>{{ item.updateTime }}</h4>
					<div class="updateItem">
						<p>{{ item.comment }}</p>
						<p class="red">录入人：{{ item.userName }}</p>
					</div>
				</div>

			</div>
		</el-dialog>
		<!-- 分页器 -->
		<div class="pageBox">
			<el-pagination @size-change="handleSizeChange" @current-change="pageChange" :current-page="cur"
				:page-sizes="[10, 20, 30, 50, 100]" :page-size="pageSize" layout="total, sizes, prev, pager, next, jumper"
				:total="totalNum" background></el-pagination>
		</div>

	</div>
</template>

<script>
import XLSX from 'xlsx';
export default {
	components: {
		perMgAddRemarks: () => import("../pageComponents/perMgAddRemarks.vue"),
		comTable: () => import("../commonComponents/comTable.vue"),
		comInput: () => import("../commonComponents/comInput.vue"),
		matMgUploadResume: () => import("../pageComponents/matMgUploadResume.vue"),
		comResume: () => import("../commonComponents/comResume.vue"),

	},
	data() {
		return {
			formUser: {
				name: '',
			},
			countProcess: 0,
			numProcess: 0,
			processMark: false,
			pageSizeExport: 20,
			curExport: 1,
			totalExport: 0,
			exportNum: 0,
			textareaRemark: '',
			formSeach: {
				name: '',
				sex: '',
				telnum: '',
				jobName: '',
				region: '',
				tradeCode: '',
				tradeName: '',
				pageNum: this.cur,
				pageSize: this.pageSize,
			},
			formExport: {
				userName: localStorage.getItem('checkHuman'),
				userId: localStorage.getItem('userid'),
				name: '',
				librarianId: '',
				telnum: "",
				sex: "",
				librarianId: "",
				age: "",
				region: "",
				cardNum: "",
				tradeName: "",
				jobName: "",
				salaryExpectation: "",
				originalCompany: "",
				originalCity: "",
				annualSalary: "",
				type: "",
				belows: '',
				projectBelongs: '',
				projectBelong: '',
				comment: '',
				workStatus: '',
				projectId: '',
			},
			processNum: 0,
			formItem: {
				item: [{
					label: '姓名',
					placeholder: '请输入姓名',
					title: 'name',
				},
				{
					label: '项目归属',
					placeholder: '请输入项目归属',
					title: 'projectBelong',
				},
				{
					label: '性别',
					placeholder: '请输入性别',
					title: 'sex',
				},
				{
					label: '年龄',
					placeholder: '请输入年龄',
					title: 'age',
				},
				{
					label: '简历',
					placeholder: '请输入简历',
					title: 'cardNum',
				},
				{
					label: '手机号码',
					placeholder: '请输入手机号码',
					title: 'telnum',
				},
				{
					label: '状态',
					placeholder: '请输入身份证号码',
					title: 'workStatus',
				},

				{
					label: '居住地',
					placeholder: '请输入居住地',
					title: 'region',
				},
				{
					label: '面试时间',
					placeholder: '请输入面试时间',
					title: 'interviewTime',
				},
				{
					label: '身份证号码',
					placeholder: '请输入身份证号码',
					title: 'cardNum',
				},
				{
					label: '职能',
					placeholder: '请输入身份证号码',
					title: 'tradeName',
				},
				{
					label: '期望薪资',
					placeholder: '请输入期望薪资',
					title: 'salaryExpectation',
				},
				{
					label: '原工作单位',
					placeholder: '请输入原工作单位',
					title: 'originalCompany',
				},
				{
					label: '原工作城市',
					placeholder: '请输入原工作城市',
					title: 'originalCity',
				},
				{
					label: '原年薪',
					placeholder: '请输入原年 薪',
					title: 'annualSalary',
				},
				{
					label: '跳槽意向程度',
					placeholder: '请输入跳槽意向程度',
					title: 'hoppingIntention',
				},
				{
					label: '备注',
					placeholder: '请输入备注',
					title: 'comment',
				},

				],

			},
			partList: [],
			serchKey: '',
			/* 筛选数据 */
			search: {
				entryName: '',
				options: [],
				value: ''
			},
			widPersnt: '80%',
			toolDialog: {
				exportShow: false,
				title: '招聘信息录入',

			},
			/* 简历模板数据 */
			remuseData: {
				showDialog: false, //显示弹窗
				title: '简历列表', //标题
				list: [
					/* {
						title: '一、简历',
					} */
				],
				userInfo: {}, //当前被操作人员信息
			},
			uploadData: {
				showDialog: false, //显示弹窗
				title: '上传简历', //标题
				fileList: [], //上传简历列表
			},
			/* 主体数据列表 */
			remarksData: {
				showDialog: false, //显示弹窗
				title: '查看备注', //标题
			},
			exportData: {
				list: [{
					title: '姓名',
					prop: 'name',
					isClick: false
				},
				{
					title: '年龄',
					prop: 'age',
					isClick: false
				},
				{
					title: '性别',
					prop: 'sex',
					isClick: false
				},
				{
					title: '手机号',
					prop: 'telnum',
					isClick: false
				},
				{
					title: '居住地',
					prop: 'region',
					isClick: false
				},
				{
					title: '身份证号码',
					prop: 'cardNum',
					isClick: true,
					eventName: 'markDia'

				},
				{
					title: '职能',
					prop: 'tradeName',
					isClick: false,
				},
				{
					title: '职位名称',
					prop: 'jobName',
					isClick: false,
				},
				{
					title: '期望薪资',
					prop: 'salaryExpectation',
					isClick: false,
				},
				{
					title: '原工作单位',
					prop: 'originalCompany',
					isClick: false,
				},
				{
					title: '原工作城市',
					prop: 'originalCity',
					isClick: false,
				},
				{
					title: '原年薪',
					prop: 'annualSalary',
					isClick: false
				},
				{
					title: '跳槽意向程度',
					prop: 'hoppingIntention',
					isClick: false
				},
				],
				noOperation: false, //是否有操作项
				operation: [ //操作项内容

				],
				data: [
					/* {
						projectName: '物险',						//项目名称
						createTime: '2020-1-55',					//新增时间
						entryNumber: 20,							//入职量
						turnover: '20%',							//离职率
						suspendTime: '2020-5-12',					//中止时间
						projectRemark: 'xxx',						//备注
						suspendStatus: '已中止',						//操作
					}, */
				]
			},
			updateList: [],
			remarkList: [],
			tableData: {
				list: [{
					title: '姓名',
					prop: 'name',
					isClick: false
				},
				{
					title: '性别',
					prop: 'sex',
					isClick: false
				},
				{
					title: '年龄',
					prop: 'age',
					isClick: false
				},
				{
					title: '手机号',
					prop: 'telnum',
					isClick: false
				},
				{
					title: '居住地',
					prop: 'region',
					isClick: false
				},
				{
					title: '身份证号码',
					prop: 'cardNum',
					isClick: false,
					eventName: 'markDia'

				},
				{
					title: '职能',
					prop: 'tradeName',
					isClick: false,
				},
				{
					title: '职位名称',
					prop: 'jobName',
					isClick: false,
				},
				{
					title: '期望薪资',
					prop: 'salaryExpectation',
					isClick: false,
				},
				{
					title: '原工作单位',
					prop: 'originalCompany',
					isClick: false,
				},
				{
					title: '原年薪',
					prop: 'annualSalary',
					isClick: false
				},
				{
					title: '原工作城市',
					prop: 'originalCity',
					isClick: false
				},
				{
					title: '跳槽意向程度',
					prop: 'hoppingIntention',
					isClick: false
				},

				{
					title: '数据来源',
					prop: 'type',
					isClick: false
				},
				{
					title: '最新备注',
					prop: 'newMark',
					isClick: true,
					eventName: 'changeRemark',

				},
				{
					title: '简历',
					prop: 'resumeBox',
					isClick: false
				},
				{
					title: '操作',
					prop: 'opration',
					isClick: false
				},

				],
				noOperation: true, //是否有操作项
				operation: [ //操作项内容
					{
						name: '修改明细',
						isBtn: false,
						title: 'upadteDetail'
					},
					{
						name: '备注明细',
						isBtn: false,
						title: 'remarkDetail'
					},
					{
						name: '招聘信息录入',
						isBtn: false,
						title: 'signUp'
					},
				],

				data: [
					/* {
						projectName: '物险',						//项目名称
						createTime: '2020-1-55',					//新增时间
						entryNumber: 20,							//入职量
						turnover: '20%',							//离职率
						suspendTime: '2020-5-12',					//中止时间
						projectRemark: 'xxx',						//备注
						suspendStatus: '已中止',						//操作
					}, */
				]
			},
			/* 弹窗数据 */
			inputData: {
				recruitmentChannel: [],
				showDialog: false, //显示弹窗
				title: '新增项目', //标题
				dialogContent: [{
					title: '公司名称:',
					value: 'companyName'
				},
				{
					title: '岗位名称:',
					value: 'positionName'
				},
				{
					title: '招聘渠道:',
					value: 'recruitmentChannel'
				},
				],
				form: {
					projectRemark: '',
				}
			},
			allData: [],
			librarianObj: {},
			belongList: [],
			userInfo: {},
			workersList: [],

			/* 分页功能数据 */
			cur: 1,
			pageSize: 10,
			totalNum: 0, //总共有多少条数据,根据这个数据去适配页数
			projectBlongsObj: '',
		}
	},
	created() {
		// this.init();
		this.getSearchList()
		this.initBase()
		this.initData()

	},
	methods: {
		submiteRemark() {
			let params = {
				librarianId: this.librarianObj.librarianId,
				changedFront: this.librarianObj.plist[0].comment,
				changedQueen: this.textareaRemark,
				grade: '7',
				userId: localStorage.getItem('userid'),
				userName: '总帐号',
				// projectId: msg.projectId

			}

			this.$telAxios.post('/v1/librarian/insertDetail', params).then(res => {
				console.log(res);
				if (res.data.code === 1000) {
					this.toolDialog.exportShow = false;
					this.initBase()
				} else {
					this.$message({
						message: res.data.message,
						type: 'warning'
					})
				}
			})
		},
		handleChangeCode(data, index) {
			console.log(data);
			if (data.length == 0) {
				return this.formSeach.tradeName = ''
			}
			if (index == '11') {
				this.formSeach.tradeName = this.$refs.cascader.getCheckedNodes()[0].label
			}
			if (index == '22') {
				this.workersList.forEach(res => {
					res.children.forEach(res1 => {
						res1.children.forEach(res2 => {
							if (data[2] == res2.value) {
								this.formExport.tradeName = res2.label
							}
						})
					})
				})
			}
			console.log(this.formSeach.tradeName);
			console.log(this.formExport.tradeName);
		},
		initData() {
			this.userInfo = eval('(' + localStorage.getItem('userinfo') + ')');
			console.log(this.userInfo);
			if (this.userInfo.grade != '20') {
				this.tableData.operation = [ //操作项内容
					{
						name: '修改明细',
						isBtn: false,
						title: 'upadteDetail'
					},
					{
						name: '备注明细',
						isBtn: false,
						title: 'remarkDetail'
					},
					
					
					 
				]
			}
			let workers = require('@/assets/mask/positionList.json');
			this.workersList = workers.position; //职能类型
		},
		sureEnter() {
			console.log(this.formExport);
			let slist = []
			slist.push(this.formExport.remark)
			this.formExport.userName = localStorage.getItem('checkHuman')
			this.formExport.userId = localStorage.getItem('userid')
			this.formExport.projectId = this.projectBlongsObj

			this.belongList.forEach(res => {
				if (res.projectId == this.projectBlongsObj) {
					this.formExport.projectBelongs = res.projectBlongs
					console.log(this.formExport.projectBelongs);
				}
			})
			// Object.assign(this.formExport,{slist})
			delete this.formExport['plist'];
			this.$ceshiAxios.post('v1/librarian/wareHouseInput', this.formExport).then(res => {
				console.log(res);
				if (res.data.code === 1) {
					this.toolDialog.exportShow = false
					this.$message.success('操作成功 ')
					this.formSeach.tradeCode = []
					this.initBase()
				}
			})
		},
		getLabel(data) {
			// this.=data.projectBlongs
			this.projectBlongsObj = data
		},
		getType(data) {
			console.log(data);

		},
		getSearchList(mark) {
			let data = {}

			let url = '/v1/librarian/projectBelongsList'
			this.$telAxios.get(url, data).then(res => {
				this.belongList = res.data.data
			})
		},
		changeRemark(row) {
			console.log(row)
			this.toolDialog.title = '备注'
			this.widPersnt = '35%'
			this.librarianObj = row
			this.textareaRemark = row.plist[0].comment
			this.toolDialog.exportShow = true
		},
		remarkDetail(row) {
			this.toolDialog.exportShow = true
			this.toolDialog.title = '备注明细'
			this.widPersnt = '35%'
			let data = {
				librarianId: row.librarianId
			}
			this.$ceshiAxios.post('/v1/librarian/selectPostscriptVoList', data).then(res => {
				console.log(res);
				this.remarkList = res.data.data.plist
			})

		},
		signUp(data) {
			this.formExport = data
			console.log(data);
			this.toolDialog.exportShow = true
			this.toolDialog.title = '招聘信息录入'
			this.lookResume(data)
			this.remuseData.showDialog = false
			this.widPersnt = '85%'
		},
		upadteDetail(row) {
			this.toolDialog.exportShow = true
			this.toolDialog.title = '修改明细'
			this.widPersnt = '35%'
			let data = {
				librarianId: row.librarianId,
				pageNum: 1,
				pageSize: 10
			}
			this.$ceshiAxios.post('v1/librarian/selectDetailBylibrarianId', data).then(res => {
				console.log(res);
				this.updateList = res.data.data.dlist
				let garedName = {
					1: '姓名',
					2: '手机号',
					3: '岗位',
					4: '工作状态',
					5: '项目归属',
					6: '标注',
					7: '新增备注',
					8: '上传简历',
					9: '放入回收站',
					10: '性别',
					11: '年龄',
					12: '学历',
					13: '籍贯',
					14: '现住址',
					15: '期望岗位',
					16: '面试时间',
					17: '招聘渠道',
					18: '居住地',
					19: '身份证号码',
					20: '职能',
					21: '职位',
					22: '职位',
					23: '原公司城市',
					24: '原工作单位',
					25: '原年薪',
				}
				this.updateList.forEach(item => {
					item.garedName = garedName[item.grade]

					if (item.grade == 4) {
						if (item.changedFront == 1) {
							item.changedFront = '沟通'
						} else if (item.changedFront == 2) {
							item.changedFront = '通知面试'
						} else if (item.changedFront == 3) {
							item.changedFront = '实到面试'
						} else if (item.changedFront == 4) {
							item.changedFront = '实到复试'
						} else if (item.changedFront == 5) {
							item.changedFront = '录取'
						} else if (item.changedFront == 6) {
							item.changedFront = '到岗'
						} else if (item.changedFront == 7) {
							item.changedFront = '入职'
						}

						if (item.changedQueen == 1) {
							item.changedQueen = '沟通'
						} else if (item.changedQueen == 2) {
							item.changedQueen = '通知面试'
						} else if (item.changedQueen == 3) {
							item.changedQueen = '实到面试'
						} else if (item.changedQueen == 4) {
							item.changedQueen = '实到复试'
						} else if (item.changedQueen == 5) {
							item.changedQueen = '录取'
						} else if (item.changedQueen == 6) {
							item.changedQueen = '到岗'
						} else if (item.changedQueen == 7) {
							item.changedQueen = '入职'
						}

					}

				})
			})
		},



		handleClose() {
			this.toolDialog.exportShow = false
			this.formSeach.tradeCode = []
			this.allData = []
		},
		//人才库的数据
		initBase() {
			this.formSeach.pageNum = this.cur
			this.formSeach.pageSize = this.pageSize
			this.$ceshiAxios.post('v1/librarian/Talentpool', this.formSeach).then(res => {
				console.log(res);
				this.tableData.data = res.data.data.llist
				this.tableData.noOperation =false
				this.tableData.data.forEach(res => {
					res.noOperation = true
					if (res.plist.length > 0) {
						res.newMark = res.plist[0].comment
					}

					if(res.recruitmentStatus==1){
						res.operation=[ //操作项内容
					{
						name: '修改明细',
						isBtn: false,
						title: 'upadteDetail'
					},
					{
						name: '备注明细',
						isBtn: false,
						title: 'remarkDetail'
					},
					{
						name: '招聘信息录入',
						isBtn: false,
						title: 'signUp'
					},
				]
					}else if(res.recruitmentStatus==2){
						res.operation=[ //操作项内容
					{
						name: '修改明细',
						isBtn: false,
						title: 'upadteDetail'
					},
					{
						name: '备注明细',
						isBtn: false,
						title: 'remarkDetail'
					},
					{
						name: '招聘信息已录入',
						isBtn: false,
						title: 'remarkDetail',
						red:true  
					},
				]
					}
				})
				console.log(this.tableData);
				this.totalNum = Math.abs(res.data.data.totalNum)
			})


		},
		lookResume(row) {
			console.log(row);
			this.remuseData.userInfo = row
			this.remuseData.showDialog = true
			this.$telAxios.post('/v1/librarian/selectFlexibileResumeList', {
				librarianId: row.librarianId
			}).then(res => {
				console.log(res);
				if (res.data.code === 1000) {
					this.remuseData.list = res.data.data;
				} else {
					this.$message({
						message: res.data.message,
						type: 'warning'
					})
				}
			})
		},
		uploadResume(row) {
			console.log(row);
			this.uploadData.userInfo = row
			this.uploadData.showDialog = true
		},

		updateView(msg) {
			console.log(msg);
			let params = {
				librarianId: this.uploadData.userInfo.librarianId,
				changedFront: '上传一条简历',
				changedQueen: '上传的简历名为：' + msg,
				grade: '8',
				userId: localStorage.getItem('userid'),
				userName: localStorage.getItem('checkHuman'),
				projectId: msg.projectId

			}

			this.$telAxios.post('/v1/librarian/insertDetail', params).then(res => {
				console.log(res);
				if (res.data.code === 1000) {
					this.uploadData.showDialog = false;
				} else {
					this.$message({
						message: res.data.message,
						type: 'warning'
					})
				}
			})
			// this.searchData(this.search.data);
		},

		//解析excel   
		analysis(file) {
			return new Promise(function (resolve, reject) {
				const reader = new FileReader();
				reader.onload = function (e) {
					const data = e.target.result;
					let datajson = XLSX.read(data, {
						type: "binary"
					});
					const result = [];
					datajson.SheetNames.forEach(sheetName => {
						result.push({
							sheetName: sheetName,
							sheet: XLSX.utils.sheet_to_json(datajson.Sheets[sheetName])
						});
					});
					resolve(result);
				};
				reader.readAsBinaryString(file.file);
			});
		},

		// 导入文件
		getExcel(file) {
			const loading = this.$loading({
				lock: true,
				text: 'Loading',
				spinner: 'el-icon-loading',
				background: 'rgba(0, 0, 0, 0.7)'
			});
			console.log(file);
			const types = file.file.name.split(".")[1]; //获取文件后缀
			const fileType = ["xlsx", "xls"].some(
				item => item === types
			);
			if (!fileType) {
				this.$message("格式错误！请重新选择");
				return;
			}
			let data = []

			console.log(fileType);
			this.analysis(file).then(tableJson => {
				console.log(tableJson);
				if (tableJson && tableJson.length > 0) {
					//成功解析出数据
					let dataExcel = tableJson[0];
					console.log("数据", dataExcel);
					let tableData = []
					tableData = dataExcel.sheet

					tableData.map((item) => {
						let obj = {
							name: item['姓名'],
							sex: item['性别'],
							age: item['年龄'],
							telnum: item['手机号'],
							region: item['居住地'],
							cardNum: item['身份证号'],
							tradeName: item['职能'],
							jobName: item['职位名称'],
							salaryExpectation: item['期望薪资'],
							originalCompany: item['原工作单位'],
							originalCity: item['原工作城市'],
							annualSalary: item['原年薪'],
							hoppingIntention: item['跳槽意向程度']
						}
						data.push(obj)
					})
					console.log(data);


					if (data.length > 1000) {
						this.allData = data
						this.totalExport = data.length
						this.partList = this.returnAllPageFunc(this.pageSizeExport, data)
						this.exportData.data = this.returnAllPageFunc(this.pageSizeExport, data)[0].list
						this.exportNum = this.exportData.data
					} else {
						this.exportData.data = data
					}

					this.toolDialog.title = '导入数据'
					this.toolDialog.exportShow = true
					if (this.toolDialog.exportShow) {
						loading.close();
					}
				}
			});
		},
		//数组分页
		returnAllPageFunc(pageSize, arr) {
			let pageNum = 1
			let pageObj = {
				pageNum: 1,
				list: []
			}
			let pageResult = []

			let newArr = JSON.parse(JSON.stringify(arr))
			let totalPage = newArr.length ? Math.ceil(arr.length / pageSize) : 0 // 计算总页数

			for (let i = 1; i <= totalPage; i++) {
				if (totalPage == 1) {
					pageNum += 1
					pageObj.list = newArr.splice(0, arr.length)
				} else if (i <= totalPage) {
					pageNum += 1
					pageObj.list = newArr.splice(0, pageSize)
				} else {
					pageObj.list = newArr.splice(0, arr.length % pageSize)
				}
				pageResult.push(pageObj)
				pageObj = {
					pageNum: pageNum,
					list: []
				}
			}
			console.log(`分页：${JSON.stringify(pageResult)}`)
			return pageResult
		},

		//分批
		async spliceData(data, count) {
			const da = []
			console.log(data.length)
			let num = data.length / count
			console.log(num)
			console.log(typeof (num))
			const loading = this.$loading({
				lock: true,
				text: 'Loading',
				spinner: 'el-icon-loading',
				background: 'rgba(0, 0, 0, 0.7)'
			});
			for (var i = 1; i <= num + 1; i++) {
				console.log(i, 'i')
				data = this.allData.slice(count * (i - 1), count * i);
				console.log(data)
				this.processMark = true;
				this.numProcess = num
				this.$ceshiAxios.post('v1/librarian/inserLibrarianList', data).then(res => {
					if (res.data.code == 1) {
						console.log('不读');
						this.countProcess++
						this.processNum = this.countProcess / this.numProcess
						console.log(this.processNum)
						if (this.processNum > 0.9) {
							this.processNum = 1
							this.processMark = false
							loading.close();
							this.$message.success('导入成功!')
							this.toolDialog.exportShow = false
							this.initBase()
						}
					}
				})
			}
			console.log(da)
			console.log(da.length)
		},
		subExport() {
			let data = []
			if (this.allData != []) {
				// data = this.allData.splice(0, 5000)
				this.spliceData(this.allData, 1000)
				console.log(data)
			} else {
				data = this.exportData.data
				this.$ceshiAxios.post('v1/librarian/inserLibrarianList', data).then(res => {
					if (res.data.code == 1) {
						this.$message.success('导入成功!')
						this.toolDialog.exportShow = false
						this.initBase()
					}
				})
			}



		},

		markDia(data) {
			console.log(data);
			this.remarksData.textarea = data.projectRemarkDia;
			if (data.projectRemarkDia) {
				this.remarksData.showDialog = true;
			}

		},

		statuss() { },
		editData(row, index) {
			console.log(row);
			this.inputData.showDialog = true;
			this.inputData.type = '编辑项目';
			this.inputData.title = '编辑项目';
			this.inputData.data = row
			let recruitmentChannel = row.recruitmentChannel.split('\n', -1)
			recruitmentChannel.pop()
			this.inputData.recruitmentChannel = recruitmentChannel
			console.log(recruitmentChannel);
		},
		//初始化
		init() {
			localStorage.setItem('pageTitle', '项目管理');
			this.$store.dispatch('setPageTitle', localStorage.getItem('pageTitle'));
			// this.getDataList();	
			this.getOptionsList();
		},
		//获取搜索列表数据
		getOptionsList() {
			let data = {
				pageNum: this.cur, //页码
				pageSize: this.pageSize, //每页条疏忽
				serchKey: this.serchKey //查询关键字
			}
			this.$telAxios.post('/v1/librarian/selectProjectByList', data).then(res => {
				console.log(res);
				this.totalNum = Math.abs(res.data.data.totalNum)
				if (res.data.code === 1000) {
					res.data.data.plist.forEach(item => {
						item.projectRemarks = item.projectRemark
						if (item.projectRemarks.length > 10) {
							item.projectRemarks = item.projectRemarks.substring(0, 10) + '....'
							item.projectRemarkDia = item.projectRemark
						}
						if (item.rlist.length > 0) {
							item.rlist.forEach(data => {
								item.recruitmentChannel += data + '\n'
							})
							item.recruitmentChannel = item.recruitmentChannel.substring(9)
						}
						item.edit = '编辑'
						if (item.suspendStatus == '1') {
							item.suspendStatus = '紧急'
						} else if (item.suspendStatus == '2') {
							item.suspendStatus = '正常'
						} else {
							item.suspendStatus = '暂停'
						}
						this.tableData.data = res.data.data.plist;
					})
				} else {
					this.$message({
						message: res.data.message,
						type: 'warning'
					})
				}
			})
		},
		//获取项目列表
		getDataList(data) {
			let params = {
				pageSize: this.pageSize,
				pageNum: this.cur,
				serchKey: this.serchKey
			};
			if (data) {
				params.projectName = data
			};
			this.$telAxios.post('/v1/librarian/selectProjectByList', params).then(res => {
				console.log(res);
				this.totalNum = Math.abs(res.data.data.totalNum)
				if (res.data.code === 1000) {
					res.data.data.plist.forEach(item => {
						item.projectRemarks = item.projectRemark
						if (item.projectRemarks.length > 10) {
							item.projectRemarks = item.projectRemarks.substring(0, 10) + '....'
							item.projectRemarkDia = item.projectRemark
						}
						if (item.rlist.length > 0) {
							item.rlist.forEach(data => {
								item.recruitmentChannel += data + '\n'
							})
							item.recruitmentChannel = item.recruitmentChannel.substring(9)
						}
						item.edit = '编辑'
						if (item.suspendStatus == '1') {
							item.suspendStatus = '紧急'
						} else if (item.suspendStatus == '2') {
							item.suspendStatus = '正常'
						} else {
							item.suspendStatus = '暂停'
						}
					})
					this.tableData.data = res.data.data.plist;
					this.totalNum = Number(res.data.data.totalNum);
				} else {
					this.$message({
						message: res.data.message,
						type: 'warning'
					})
				}
			})
		},
		//打开新增项目弹窗
		openInputDialog() {
			this.inputData.showDialog = true;
			this.inputData.type = '新增项目';
			this.inputData.title = '新增项目';

		},

		//提交新增项目数据
		subData(data) {
			console.log(data);
			this.inputData.showDialog = false;
			this.getDataList();
			this.getOptionsList();
		},
		//中止项目弹窗
		stopProject(data) {
			console.log(data);
			if (data.suspendStatus == '2') {
				this.$confirm('是否确认中止该项目？', '项目中止', {
					confirmButtonText: '确定',
					cancelButtonText: '取消',
					type: 'warning',
				}).then(() => {
					this.$telAxios.post('/v1/librarian/updateProjectSuspendStatus', {
						projectId: data.projectId,
						projectName: data.projectName
					}).then(res => {
						console.log(res);
						if (res.data.code === 1000) {
							this.$message({
								message: '项目中止成功！',
								type: 'warning'
							})
							this.getDataList();
						} else {
							this.$message({
								message: res.data.message,
								type: 'warning'
							})
						}
					})
				}, () => {
					this.$message({
						message: '项目中止已取消！',
						type: 'info'
					})
				})
			} else {
				this.$message({
					message: '该项目已经中止，无法进行操作！',
					type: 'warning'
				})
			}
		},
		// 页码数
		handleSizeChangeExport(data) {
			this.partList = this.returnAllPageFunc(data, this.allData)
			this.exportData.data = this.returnAllPageFunc(data, this.allData)[this.curExport - 1].list
			console.log(this.exportData.data)
			console.log(this.pageSizeExport)
			this.pageSizeExport = data
		},

		pageChangeExport(data) {
			console.log(this.partList)
			this.curExport = data
			this.partList.forEach(res => {
				if (res.pageNum == this.curExport) {
					this.exportData.data = res.list
				}
			})
			console.log(this.exportData.data)
		},

		//当前页是第几页,点击的第几页的时候调用这个函数
		pageChange(p) {
			// 点击的时候传过来一个参数，这个参数就是所点击的当前页数，
			// 然后把这个当前页数转换成字符串形式赋值给page，
			// 然后把page这个参数传给search这个方法
			this.cur = p;
			this.formSeach.pageNum = p
			this.initBase()
		},
		//每页有多少条,10,20,50等,点击选择的时候调用这个方法
		handleSizeChange(val) {
			this.pageSize = val;
			this.formSeach.pageSize = val
			this.initBase()
		},
	}
}
</script>

<style scoped="scoped">
.container {
	position: relative;
	background-color: #fff;
	height: 100%;
	padding-left: 20px;
}

.proocessBox {

	width: 500px;
	position: absolute;
	top: 50%;
	left: 26%;
	z-index: 9999;
}

.header-title {
	padding: 10px 0 20px 0;
	border-bottom: 1px solid #D2D2D2;
}

.header-title span {
	width: 15px;
	float: left;
	height: 30px;
	background-color: #0064E4;
	margin-right: 20px;
}

.header-title p {
	font-size: 16px;
	line-height: 30px;
	float: left;
	font-family: PingFang SC;
}

.header-title .fr {
	float: right;
	margin-right: 30px;
	cursor: pointer;
	color: #5492CC;
}

.upload-demo {
	display: inline-block;
}

.serchBtn {
	border-radius: 5px;
	padding: 8px 25px;
	border: none;

}

.exporBtn {
	margin-top: 40px;
	padding: 16px 38px;
	color: white;
	background: #5492CC;
}

.btn1 {
	background-color: #5492CC;
	color: white;
	margin-right: 20px;
}

.btn2 {
	background-color: white;
	color: #5492CC;
	border: 1px solid #5492CC;
}

.seachBox {
	padding: 10px 20px;
}

.seachBox /deep/.el-row {
	margin-top: 20px;
}

.seachBox .el-input {
	width: 240px;
}

.seachBox span {
	display: inline-block;
	width: 70px;
}

.projectTab /deep/ .caret-wrapper {
	display: none;
}

.project-screen {
	width: 600px;
	margin: 30px auto 50px;
}

.screen-input {
	width: 470px;
}

.center {
	text-align: center;
	padding-top: 20px;
	border-bottom: 1px solid #707070;
	padding-bottom: 20px;
}


.remarks-content {
	width: 500px;
	margin: 20px auto;
	padding-bottom: 20px;
	text-align: center;
}

.remarks-content .sub {
	margin: 20px;
}

.exportBox {
	padding-top: 20px;
	padding-bottom: 60px;
	height: 600px;
	padding-left: 20px;
	padding-right: 20px;
	overflow-y: scroll;
	text-align: center;
}

.inputBox {
	padding: 20px;
}

.textAl {
	text-align: center;
}

.updateMark {
	text-align: center;
}

.updateItem {
	text-align: left;
	background: #F7F7F7;
	border-radius: 10px;
	padding: 10px;
	margin-top: 10px;
}

.red {
	color: red !important;
}

.updateItem p {
	font-size: 18px;
	font-family: PingFang SC;
	font-weight: 500;
	color: #000000;
	line-height: 26px;
}

.exportBox::-webkit-scrollbar {
	width: 8px;
	height: 3px;
}

.width {
	width: 450px;
}

.pBox {
	width: 450px;
	text-align: center;
	/* border: 1px solid #DCDFE6; */
	border-radius: 10px;
	height: 42px;
	cursor: pointer;
}

.pBox .upIcon {
	font-size: 40px;
}

.itemForm {
	margin-right: 80px;
}

/* 滚动条的内层滑轨背景颜色 */
.exportBox::-webkit-scrollbar-track-piece {
	background-color: #fff;
}

/* 滚动条的外层滑轨背景颜色 */
.exportBox::-webkit-scrollbar-track {
	background-color: #fff;
}

/* 滚动条的内层滑块颜色 */
.exportBox::-webkit-scrollbar-thumb {
	border-radius: 10px;
	box-shadow: inset 0 0 0px rgba(237, 237, 237, 0.5);
	background-color: black;
}


.screen-btn {
	margin-left: 30px;
	width: 100px;
	height: 40px;
	background-color: rgb(86, 145, 202);
}

.pageBox {
	margin-top: 20px;
}



/deep/.el-table th {
	height: 46px;
	font-size: 14px;
	color: #727272;
	background-color: rgb(86, 145, 202);
	border: rgb(86, 145, 202);
	color: white;
}
</style>
